﻿using System;
using System.Windows.Forms;
using bbtpClient.Entities;
using bbtpClient.Controllers;

namespace bbtpClient
{
    public partial class EditTransportCompaniesListForm : Form
    {
        public EditTransportCompaniesListForm(TransportCompanyHead[] companies)
        {
            InitializeComponent();
            label_UserName.Text = UserInfo.Name;
            companies_listBox.Items.AddRange(companies);
            companies_listBox.Invalidate();
        }

        private void editCompany_button_Click(object sender, EventArgs e)
        {
            int selectedCompanyIndex = companies_listBox.SelectedIndex;
            TransportCompanyHead selectedCompany = (TransportCompanyHead)companies_listBox.Items[selectedCompanyIndex];
            TransportManagerController.ShowEditTransportCompanyForm(selectedCompany.id);
        }

        private void delete_button_Click(object sender, EventArgs e)
        {
            int selectedCompanyIndex = companies_listBox.SelectedIndex;
            TransportCompanyHead selectedCompany = (TransportCompanyHead)companies_listBox.Items[selectedCompanyIndex];
            TransportManagerController.DeleteTransportCompany(selectedCompany.id, this);
        }

        public void DeleteSelectedCompanyFromList()
        {
            int selectedCompanyIndex = companies_listBox.SelectedIndex;
            companies_listBox.Items.RemoveAt(selectedCompanyIndex); 
        }

        private void exit_button_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}